package tech.eyao.hs60x.serviceImpl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tech.eyao.hs60x.dao.CallRecordDao;
import tech.eyao.hs60x.dto.BaseResult;
import tech.eyao.hs60x.enums.ExceptionCodeEnum;
import tech.eyao.hs60x.model.domain.CallRecordsDO;
import tech.eyao.hs60x.service.CallRecordService;

/**
 * 类CallRecordServiceImpl.java的实现描述：加通话记录表，增加入库查询接口
 * 
 * @author fengjianchao 2018年1月21日 下午8:17:36
 */
@Service
public class CallRecordServiceImpl implements CallRecordService {
    private static final Logger logger = LoggerFactory.getLogger(CallRecordServiceImpl.class);
    @Autowired
    private CallRecordDao       callRecordDaoImpl;

    @Override
    public BaseResult insertCallLog(CallRecordsDO callRecordsDO) {
        try {
            // 基本验证
            if (null == callRecordsDO) {
                return BaseResult.isFailure(ExceptionCodeEnum.ERROR_PARAMERROR.getCode(),
                        ExceptionCodeEnum.ERROR_PARAMERROR.getMessage());
            }
            if (callRecordDaoImpl.insertCallLog(callRecordsDO)) {
                return BaseResult.isSuccess();
            }

        } catch (Exception e) {
            logger.info("insertCallLog fail:{}", e.getMessage());
            return BaseResult.isDeFaultFailure();
        }
        return null;

    }

    /**
     * 根据设备号/来源获取通话记录
     */
    public List<CallRecordsDO> queryCallLogListByConndition(CallRecordsDO callRecordsDO) {
        try {
            // TODO Auto-generated method stub
            if (null == callRecordsDO || null == callRecordsDO.getWatchId()) {
                return null;
            }
            List<CallRecordsDO> callRecordsDOList = callRecordDaoImpl.queryCallLogListByConndition(callRecordsDO);
            return callRecordsDOList;
        } catch (Exception e) {
            logger.info("queryCallLogListByConndition fail:{}", e.getMessage());
        }
        return null;
    }

}
